self.addEventListener("message", (ev) => {
  // self.console.log("message",ev);
  // let data = ev.data;
  let start_day = ev.data.start_day;
  let end_day = ev.data.end_day;
  let dimension = ev.data.dimension;
  let random_id = ev.data.random_id;
  let loc_2_name = ev.data.loc_2_name;
  /**@type {Array<Number>} */
  let location_ids = ev.data.location_ids;
  console.log('location_ids', location_ids);
  let timeline_data = ev.data.timeline_data;
  // debugger
  let date_day_start = new Date(`2020-04-${start_day} 00:00:00`);
  let date_day_end = new Date(`2020-04-${end_day} 24:00:00`);
  let filtered = timeline_data
  filtered = filtered.filter(e => e.time_stamp >= date_day_start.valueOf() && e.time_stamp <= date_day_end.valueOf());
  console.log("step 1", filtered.length);
  filtered = filtered.filter(e => !!e[dimension]);
  console.log("step 2", filtered.length);
  filtered = filtered.filter(e => location_ids.includes(e['location']));
  console.log("step 3", filtered.length);
  /**@description 按照location 分一下 
   * @type {Array<{name:String,data:[],location:Number}>}
  */
  let results = [];
  for(let loc of location_ids){
    let f = filtered.filter(e=>e['location']==loc);
    results.push({
      name:loc_2_name[loc],
      data:f,
      location:loc
    })
  }


  self.postMessage({
    random_id: random_id,
    filtered_results:results
  })
}, false);
self.console.log("worker run!")